package com.itheima3.web.exceptionDemo;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice//@ControllerAdvice
public class MyEx {
//@ExceptionHandler(Exception.class)
    @ExceptionHandler(Exception.class)
    public ModelAndView handle(Exception ex){
        // 判断ex的类型
        System.out.println(ex.getMessage());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("errorMsg",ex.getMessage());
        return modelAndView;
    }
}
